using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InventoryUI : MonoBehaviour
{
    [SerializeField] private GameObject itemSlotPerfabs;
    private UI_ItemSlot[] UI_ItemSlots;
    public List<InventoryItem> ivtItems;

    public void Init(int size,List<InventoryItem> ivtItems)
    { 
        this.ivtItems = ivtItems;
        CreateItemSlot(size);
    }

    private void CreateItemSlot(int size)
    {
        for (int i = 0; i < size; i++)
        {
            GameObject gobj = Instantiate(itemSlotPerfabs);
            gobj.transform.SetParent(this.transform);
        }
        UI_ItemSlots = GetComponentsInChildren<UI_ItemSlot>();

    }
    public virtual void UpdateSlotUI()
    {
        for (int i = 0; i < UI_ItemSlots.Length; i++)
        {
            if (i < ivtItems.Count)
            {
                UI_ItemSlots[i].UpdateSlot(ivtItems[i]);
            }
            else
            {
                UI_ItemSlots[i].UpdateSlot(null);
            }
        }
    }
}
